#ifndef CDACCONTROLERSINGLE_H
#define CDACCONTROLERSINGLE_H
#include <QObject>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QDateTime>
#include <QList>
#include <QDebug>
#include <QString>
#include <QChar>
#include <math.h>
#include "myhelper.h"



class CDacControlerSingle: public QSerialPort
{
public:
    typedef enum eChannel
    {
        C1=1,
        C2=2,
        ALL=0
    }ECHANNEL;

    Q_OBJECT
private:
    explicit CDacControlerSingle(QObject *parent = 0);
    explicit CDacControlerSingle(const QSerialPortInfo &serialPortInfo, QObject *parent = nullptr);
    explicit CDacControlerSingle(const QString &strPortName, QSerialPort::BaudRate baud,QObject *parent = 0);
    ~CDacControlerSingle();

    static  CDacControlerSingle *m_instanse; //饿汉单例模式
    //用于垃圾自动回收
    class GarbageCollector {
    public:
        ~GarbageCollector() {
            if (CDacControlerSingle::m_instanse) {
                delete CDacControlerSingle::m_instanse;
                CDacControlerSingle::m_instanse = nullptr;
                //qDebug()<<"huishou";
            }
        }
    };
    static GarbageCollector gc; //声明垃圾回收对象

public:
    //获得单利对象
    static CDacControlerSingle *GetSingelton()
    {
        return m_instanse;
    }
    //设置参数
    void setSerialPara(const QString &strPortName, QSerialPort::BaudRate baud);

    //对外接口
    bool set1RoadDacOutput(float volt1); //volt1:0-5V
    bool setBatterySimulatorOutput(float volt1, float radio=205); //电池模拟器输出 倍率放大radio  volt1:0-1000V
private: //两路
    bool set2RoadDacOutput(ECHANNEL channel,float volt1, float volt2); //DAC实际输出 0.000V-9.999V
    bool setBatterySimulatorOutput(ECHANNEL channel,float volt1, float volt2,float radio=205); //电池模拟器输出 倍率放大radio
signals:

public slots:
private:


    void paraInit(); //初始化参数函数
    void dealRec(); //接受处理函数
};

#endif // CDACCONTROLERSINGLE_H


/*
 *
 *
【串口DAC/正负10V输出/数字转模拟/DAC8562/单片机开发板】https://m.tb.cn/h.3wW8Bo6 点击链接，再选择浏览器咑閞；或復·制这段描述￥yDxcbFMOrlB￥后到淘寳
单路：-10V-=10V

5a 01 34 56 A5=5a 01 04 56 A5
34 56=>4.56v
04 56=>4.56V

电池模拟器=DAC+高压电源

DAC：0-5V
高压电源倍率：205

CDacControlerSingle::GetSingelton()->setSerialPara("ttyAMA3",QSerialPort::Baud38400);
CDacControlerSingle::GetSingelton()->open(QIODevice::ReadWrite);
CQtGpsSingle::GetSingelton()->write("123");

if( CQtGpsSingle::GetSingelton()->isOpen()==true)
{
    qDebug()<<tr("open true");
    CQtGpsSingle::GetSingelton()->write("hello");
    connect(CQtGpsSingle::GetSingelton(),&CQtGpsSingle::signalGetReady,this,[=]
    {
        //this->ui->lineEditTime->setText(CQtGpsSingle::GetSingelton()->getCurrentTime().toString("yyyy-MM-dd hh:mm:ss"));
        this->ui->lineEditTime->setText("QYROIUYEW");
        qDebug()<<"当前时刻："<<CQtGpsSingle::GetSingelton()->getCurrentTime()<<"纬度："<<CQtGpsSingle::GetSingelton()->getLatitudeSign()
               <<CQtGpsSingle::GetSingelton()->getLatitude()<<"纬度"<<CQtGpsSingle::GetSingelton()->getLongitudeSign()<<CQtGpsSingle::GetSingelton()->getLongitude();
    });
}

*/

